package Arrays;

/**
 * 作者:hfj
 * 功能:168.Excel列表名称
 * 日期: 2025/10/27 16:51
 */
public class ConvertToTitle {
    public static void main(String[] args) {
        int n = 28;
        System.out.println(convertToTitle(n));
    }

    public static String convertToTitle(int columnNumber) {
        StringBuilder builder = new StringBuilder();
        while (columnNumber > 0){
            switch (columnNumber % 26){
                case 1:
                    builder.append("A");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 2:
                    builder.append("B");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 3:
                    builder.append("C");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 4:
                    builder.append("D");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 5:
                    builder.append("E");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 6:
                    builder.append("F");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 7:
                    builder.append("G");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 8:
                    builder.append("H");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 9:
                    builder.append("I");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 10:
                    builder.append("J");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 11:
                    builder.append("K");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 12:
                    builder.append("L");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 13:
                    builder.append("M");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 14:
                    builder.append("N");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 15:
                    builder.append("O");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 16:
                    builder.append("P");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 17:
                    builder.append("Q");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 18:
                    builder.append("R");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 19:
                    builder.append("S");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 20:
                    builder.append("T");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 21:
                    builder.append("U");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 22:
                    builder.append("V");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 23:
                    builder.append("W");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 24:
                    builder.append("X");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 25:
                    builder.append("Y");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
                case 0:
                    builder.append("Z");
                    columnNumber--;
                    columnNumber /= 26;
                    break;
            }
        }
        String res = "";
        res += builder.reverse();
        return res;
    }
}
